import React, { useEffect } from 'react'
import TabBar from '@/components/TabBar'
import { Outlet, useNavigate } from 'react-router-dom'
import { EventSys } from '@/common/EventSys'
import BackPrevButton from '@/components/BackPrevButton'

export default function App() {
    const navigate = useNavigate()
    // 路由拦截
    // 除了登录页面，都需要登录后才能访问
    let token = localStorage.getItem('token')
    useEffect(() => {
        if (!token) {
            navigate('/login')
        }
    }, [])

    // 在 app 里面先订阅 登录超时 的事件
    EventSys.on('login_timeout', () => {
        navigate('/login')
    })

    return (
        <>
            <Outlet />
            <TabBar />
            <BackPrevButton />
        </>

    )
}
